//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_changeTarget.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);

private ["_var","_target","_x","_index"];

_index = lbCurSel 119;
_var = lbText [119,_index];

_target = objNull;

if (count BTC_r_list_names <= _index) exitWith {hint "Invalid Selection"};
if (count BTC_r_list_objects <= _index) exitWith {hint "Invalid Selection"};
if (toUpper(BTC_r_list_names select _index) != toUpper(_var)) exitWith {hint "Invalid Selection"};

_target = BTC_r_list_objects select _index;
if (isnil "_target") then { _target = objNull; };
if (typeName _target == typename "") then {
	if (markerType _target != "") then {
		BTC_r_base_spawn setPos (getMarkerPos _target);
		_target = BTC_r_base_spawn;
	} else {
		ERROR_1("Invalid Marker",_target);
		_target = objNull;
	};
};
if (typename _target != typename objNull) then {
	ERROR_1("Invalid Target",_target);
	_target = objNull;
};

if (isnil "_target" || {isnull _target}) then {
	BTC_r_base_spawn setPos (getMarkerPos BTC_respawn_marker);
	_target = BTC_r_base_spawn;
};
ctrlSetText [130, ""];
TRACE_1("New Target",ARR_4(_index,_var,_target,typeof _target));

BTC_r_mobile_selected = _target;
BTC_r_camera camSetTarget _target;
BTC_r_camera cameraEffect ["internal", "BACK"];
BTC_r_camera attachTo [_target,[-15,-15,15]];
BTC_r_camera camCommit 0;